package top.chj.day18.genericity.yingyong2;

import java.text.Collator;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Locale;

/**
 * @Auther:小陈的Java
 */
public class User2 {
    private int id;
    private String name;
    private int age;

    public User2(int id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    public User2() {
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "User2{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public static void main(String[] args) {
        User2[] user2 = new User2[3];
        user2[0] = new User2(1,"张三",18);
        user2[1] = new User2(2,"李四",18);
        user2[2] = new User2(3,"王五",19);
        Arrays.sort(user2, new Comparator<User2>() {
            public int compare(User2 o1, User2 o2) {
                if(o1.getAge()!= o2.getAge()){
                    return o1.getAge()-o2.getAge();
                }else {
                    Collator collator = Collator.getInstance(Locale.CHINA);
                    return collator.compare(o1.getName(),o2.getName());
                }
            }
        });
        System.out.println(Arrays.toString(user2));
    }
}
